/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 * File: wienerAB.c
 *
 * MATLAB Coder version            : 3.2
 * C/C++ source code generated on  : 19-Jun-2017 17:45:48
 */

/* Include Files */
#include "rt_nonfinite.h"
#include "wienerAB.h"
#include "wienerAB_emxutil.h"
#include "fft.h"
#include "power.h"
#include "abs.h"
#include "rdivide.h"
#include "wienerAB_rtwutil.h"

/* Variable Definitions */
static float buffer[400];
static float j;
static float count;
static emxArray_real32_T *noise_ps;
static boolean_T noise_ps_not_empty;
static emxArray_real32_T *G_prev;
static boolean_T G_prev_not_empty;
static emxArray_real32_T *posteri_prev;
static boolean_T posteri_prev_not_empty;
static emxArray_real32_T *overlap;
static boolean_T overlap_not_empty;
static float overlap_spl[200];
static float update;
static float SPL;

/* Function Declarations */
static float rt_roundf_snf(float u);

/* Function Definitions */

/*
 * Arguments    : float u
 * Return Type  : float
 */
static float rt_roundf_snf(float u)
{
  float y;
  if ((float)fabs(u) < 8.388608E+6F) {
    if (u >= 0.5F) {
      y = (float)floor(u + 0.5F);
    } else if (u > -0.5F) {
      y = u * 0.0F;
    } else {
      y = (float)ceil(u - 0.5F);
    }
  } else {
    y = u;
  }

  return y;
}

/*
 * Buffer to store the frames
 * Arguments    : const float frame_in[200]
 *                float spl_threshold
 *                float Srate
 *                float out[200]
 * Return Type  : void
 */
void wienerAB(const float frame_in[200], float spl_threshold, float Srate, float
              out[200])
{
  float fv0[400];
  int nB;
  double d0;
  float U2;
  static const double a[400] = { 0.079999998211860657, 0.080057032406330109,
    0.080228120088577271, 0.080513216555118561, 0.0809122622013092,
    0.08142513781785965, 0.082051731646060944, 0.082791887223720551,
    0.083645418286323547, 0.084612108767032623, 0.085691727697849274,
    0.086883999407291412, 0.088188633322715759, 0.089605309069156647,
    0.091133661568164825, 0.092773325741291046, 0.094523891806602478,
    0.0963849201798439, 0.098355956375598907, 0.1004365086555481,
    0.10262606292963028, 0.10492406785488129, 0.10732996463775635,
    0.10984314978122711, 0.11246300488710403, 0.11518887430429459,
    0.11802008748054504, 0.1209559440612793, 0.12399570643901825,
    0.12713862955570221, 0.1303839236497879, 0.13373079895973206,
    0.13717842102050781, 0.14072592556476593, 0.14437244832515717,
    0.1481170654296875, 0.15195886790752411, 0.15589688718318939,
    0.15993016958236694, 0.16405768692493439, 0.16827842593193054,
    0.17259134352207184, 0.17699536681175232, 0.18148940801620483,
    0.18607234954833984, 0.19074305891990662, 0.19550037384033203,
    0.20034310221672058, 0.20527006685733795, 0.21028004586696625,
    0.215371772646904, 0.22054401040077209, 0.2257954478263855,
    0.23112481832504272, 0.23653076589107513, 0.24201197922229767,
    0.2475670725107193, 0.25319468975067139, 0.25889343023300171,
    0.26466187834739685, 0.27049857378005981, 0.27640214562416077,
    0.28237104415893555, 0.28840383887290955, 0.29449903964996338,
    0.30065509676933289, 0.30687052011489868, 0.31314373016357422,
    0.31947323679924011, 0.32585740089416504, 0.33229464292526245,
    0.33878341317176819, 0.34532210230827332, 0.35190904140472412,
    0.35854262113571167, 0.36522120237350464, 0.37194311618804932,
    0.37870672345161438, 0.38551032543182373, 0.39235222339630127,
    0.3992307186126709, 0.40614414215087891, 0.41309076547622681,
    0.42006886005401611, 0.42707666754722595, 0.43411248922348022,
    0.44117459654808044, 0.44826117157936096, 0.45537051558494568,
    0.46250084042549133, 0.46965038776397705, 0.47681736946105957,
    0.484000027179718, 0.49119654297828674, 0.49840518832206726,
    0.50562417507171631, 0.51285165548324585, 0.520085871219635,
    0.52732497453689575, 0.53456729650497437, 0.541810929775238,
    0.54905414581298828, 0.55629509687423706, 0.56353199481964111,
    0.57076305150985718, 0.577986478805542, 0.58520054817199707,
    0.5924033522605896, 0.59959316253662109, 0.60676819086074829,
    0.61392670869827271, 0.6210668683052063, 0.62818688154220581,
    0.63528507947921753, 0.64235961437225342, 0.64940881729125977,
    0.65643084049224854, 0.663424015045166, 0.670386552810669,
    0.67731678485870361, 0.68421298265457153, 0.69107341766357422,
    0.69789636135101318, 0.70468020439147949, 0.71142315864562988,
    0.71812361478805542, 0.72477990388870239, 0.73139035701751709,
    0.73795336484909058, 0.74446731805801392, 0.75093048810958862,
    0.75734144449234009, 0.76369845867156982, 0.76999998092651367,
    0.77624452114105225, 0.78243046998977661, 0.78855627775192261,
    0.79462045431137085, 0.800621509552002, 0.80655789375305176,
    0.81242823600769043, 0.81823098659515381, 0.82396471500396729,
    0.8296281099319458, 0.8352196216583252, 0.84073793888092041,
    0.84618169069290161, 0.851549506187439, 0.85684007406234741,
    0.86205208301544189, 0.86718422174453735, 0.87223523855209351,
    0.87720388174057007, 0.882088840007782, 0.88688904047012329,
    0.89160317182540894, 0.896230161190033, 0.90076881647109985,
    0.90521794557571411, 0.90957659482955933, 0.91384351253509521,
    0.91801780462265015, 0.92209833860397339, 0.92608410120010376,
    0.92997413873672485, 0.93376743793487549, 0.937463104724884,
    0.94106024503707886, 0.94455790519714355, 0.94795525074005127,
    0.95125144720077515, 0.95444566011428833, 0.95753711462020874,
    0.9605250358581543, 0.96340864896774292, 0.96618729829788208,
    0.9688602089881897, 0.97142684459686279, 0.97388643026351929,
    0.9762384295463562, 0.97848230600357056, 0.98061740398406982,
    0.98264330625534058, 0.98455935716629028, 0.98636519908905029,
    0.98806041479110718, 0.989644467830658, 0.991117000579834,
    0.99247771501541138, 0.99372619390487671, 0.99486219882965088,
    0.99588537216186523, 0.99679553508758545, 0.99759238958358765,
    0.9982757568359375, 0.99884551763534546, 0.9993014931678772,
    0.99964356422424316, 0.99987167119979858, 0.99998575448989868,
    0.99998575448989868, 0.99987167119979858, 0.99964356422424316,
    0.9993014931678772, 0.99884551763534546, 0.9982757568359375,
    0.99759238958358765, 0.99679553508758545, 0.99588537216186523,
    0.99486219882965088, 0.99372619390487671, 0.99247771501541138,
    0.991117000579834, 0.989644467830658, 0.98806041479110718,
    0.98636519908905029, 0.98455935716629028, 0.98264330625534058,
    0.98061740398406982, 0.97848230600357056, 0.9762384295463562,
    0.97388643026351929, 0.97142684459686279, 0.9688602089881897,
    0.96618729829788208, 0.96340864896774292, 0.9605250358581543,
    0.95753711462020874, 0.95444566011428833, 0.95125144720077515,
    0.94795525074005127, 0.94455790519714355, 0.94106024503707886,
    0.937463104724884, 0.93376743793487549, 0.92997413873672485,
    0.92608410120010376, 0.92209833860397339, 0.91801780462265015,
    0.91384351253509521, 0.90957659482955933, 0.90521794557571411,
    0.90076881647109985, 0.896230161190033, 0.89160317182540894,
    0.88688904047012329, 0.882088840007782, 0.87720388174057007,
    0.87223523855209351, 0.86718422174453735, 0.86205208301544189,
    0.85684007406234741, 0.851549506187439, 0.84618169069290161,
    0.84073793888092041, 0.8352196216583252, 0.8296281099319458,
    0.82396471500396729, 0.81823098659515381, 0.81242823600769043,
    0.80655789375305176, 0.800621509552002, 0.79462045431137085,
    0.78855627775192261, 0.78243046998977661, 0.77624452114105225,
    0.76999998092651367, 0.76369845867156982, 0.75734144449234009,
    0.75093048810958862, 0.74446731805801392, 0.73795336484909058,
    0.73139035701751709, 0.72477990388870239, 0.71812361478805542,
    0.71142315864562988, 0.70468020439147949, 0.69789636135101318,
    0.69107341766357422, 0.68421298265457153, 0.67731678485870361,
    0.670386552810669, 0.663424015045166, 0.65643084049224854,
    0.64940881729125977, 0.64235961437225342, 0.63528507947921753,
    0.62818688154220581, 0.6210668683052063, 0.61392670869827271,
    0.60676819086074829, 0.59959316253662109, 0.5924033522605896,
    0.58520054817199707, 0.577986478805542, 0.57076305150985718,
    0.56353199481964111, 0.55629509687423706, 0.54905414581298828,
    0.541810929775238, 0.53456729650497437, 0.52732497453689575,
    0.520085871219635, 0.51285165548324585, 0.50562417507171631,
    0.49840518832206726, 0.49119654297828674, 0.484000027179718,
    0.47681736946105957, 0.46965038776397705, 0.46250084042549133,
    0.45537051558494568, 0.44826117157936096, 0.44117459654808044,
    0.43411248922348022, 0.42707666754722595, 0.42006886005401611,
    0.41309076547622681, 0.40614414215087891, 0.3992307186126709,
    0.39235222339630127, 0.38551032543182373, 0.37870672345161438,
    0.37194311618804932, 0.36522120237350464, 0.35854262113571167,
    0.35190904140472412, 0.34532210230827332, 0.33878341317176819,
    0.33229464292526245, 0.32585740089416504, 0.31947323679924011,
    0.31314373016357422, 0.30687052011489868, 0.30065509676933289,
    0.29449903964996338, 0.28840383887290955, 0.28237104415893555,
    0.27640214562416077, 0.27049857378005981, 0.26466187834739685,
    0.25889343023300171, 0.25319468975067139, 0.2475670725107193,
    0.24201197922229767, 0.23653076589107513, 0.23112481832504272,
    0.2257954478263855, 0.22054401040077209, 0.215371772646904,
    0.21028004586696625, 0.20527006685733795, 0.20034310221672058,
    0.19550037384033203, 0.19074305891990662, 0.18607234954833984,
    0.18148940801620483, 0.17699536681175232, 0.17259134352207184,
    0.16827842593193054, 0.16405768692493439, 0.15993016958236694,
    0.15589688718318939, 0.15195886790752411, 0.1481170654296875,
    0.14437244832515717, 0.14072592556476593, 0.13717842102050781,
    0.13373079895973206, 0.1303839236497879, 0.12713862955570221,
    0.12399570643901825, 0.1209559440612793, 0.11802008748054504,
    0.11518887430429459, 0.11246300488710403, 0.10984314978122711,
    0.10732996463775635, 0.10492406785488129, 0.10262606292963028,
    0.1004365086555481, 0.098355956375598907, 0.0963849201798439,
    0.094523891806602478, 0.092773325741291046, 0.091133661568164825,
    0.089605309069156647, 0.088188633322715759, 0.086883999407291412,
    0.085691727697849274, 0.084612108767032623, 0.083645418286323547,
    0.082791887223720551, 0.082051731646060944, 0.08142513781785965,
    0.0809122622013092, 0.080513216555118561, 0.080228120088577271,
    0.080057032406330109, 0.079999998211860657 };

  static const double b[400] = { 0.079999998211860657, 0.080057032406330109,
    0.080228120088577271, 0.080513216555118561, 0.0809122622013092,
    0.08142513781785965, 0.082051731646060944, 0.082791887223720551,
    0.083645418286323547, 0.084612108767032623, 0.085691727697849274,
    0.086883999407291412, 0.088188633322715759, 0.089605309069156647,
    0.091133661568164825, 0.092773325741291046, 0.094523891806602478,
    0.0963849201798439, 0.098355956375598907, 0.1004365086555481,
    0.10262606292963028, 0.10492406785488129, 0.10732996463775635,
    0.10984314978122711, 0.11246300488710403, 0.11518887430429459,
    0.11802008748054504, 0.1209559440612793, 0.12399570643901825,
    0.12713862955570221, 0.1303839236497879, 0.13373079895973206,
    0.13717842102050781, 0.14072592556476593, 0.14437244832515717,
    0.1481170654296875, 0.15195886790752411, 0.15589688718318939,
    0.15993016958236694, 0.16405768692493439, 0.16827842593193054,
    0.17259134352207184, 0.17699536681175232, 0.18148940801620483,
    0.18607234954833984, 0.19074305891990662, 0.19550037384033203,
    0.20034310221672058, 0.20527006685733795, 0.21028004586696625,
    0.215371772646904, 0.22054401040077209, 0.2257954478263855,
    0.23112481832504272, 0.23653076589107513, 0.24201197922229767,
    0.2475670725107193, 0.25319468975067139, 0.25889343023300171,
    0.26466187834739685, 0.27049857378005981, 0.27640214562416077,
    0.28237104415893555, 0.28840383887290955, 0.29449903964996338,
    0.30065509676933289, 0.30687052011489868, 0.31314373016357422,
    0.31947323679924011, 0.32585740089416504, 0.33229464292526245,
    0.33878341317176819, 0.34532210230827332, 0.35190904140472412,
    0.35854262113571167, 0.36522120237350464, 0.37194311618804932,
    0.37870672345161438, 0.38551032543182373, 0.39235222339630127,
    0.3992307186126709, 0.40614414215087891, 0.41309076547622681,
    0.42006886005401611, 0.42707666754722595, 0.43411248922348022,
    0.44117459654808044, 0.44826117157936096, 0.45537051558494568,
    0.46250084042549133, 0.46965038776397705, 0.47681736946105957,
    0.484000027179718, 0.49119654297828674, 0.49840518832206726,
    0.50562417507171631, 0.51285165548324585, 0.520085871219635,
    0.52732497453689575, 0.53456729650497437, 0.541810929775238,
    0.54905414581298828, 0.55629509687423706, 0.56353199481964111,
    0.57076305150985718, 0.577986478805542, 0.58520054817199707,
    0.5924033522605896, 0.59959316253662109, 0.60676819086074829,
    0.61392670869827271, 0.6210668683052063, 0.62818688154220581,
    0.63528507947921753, 0.64235961437225342, 0.64940881729125977,
    0.65643084049224854, 0.663424015045166, 0.670386552810669,
    0.67731678485870361, 0.68421298265457153, 0.69107341766357422,
    0.69789636135101318, 0.70468020439147949, 0.71142315864562988,
    0.71812361478805542, 0.72477990388870239, 0.73139035701751709,
    0.73795336484909058, 0.74446731805801392, 0.75093048810958862,
    0.75734144449234009, 0.76369845867156982, 0.76999998092651367,
    0.77624452114105225, 0.78243046998977661, 0.78855627775192261,
    0.79462045431137085, 0.800621509552002, 0.80655789375305176,
    0.81242823600769043, 0.81823098659515381, 0.82396471500396729,
    0.8296281099319458, 0.8352196216583252, 0.84073793888092041,
    0.84618169069290161, 0.851549506187439, 0.85684007406234741,
    0.86205208301544189, 0.86718422174453735, 0.87223523855209351,
    0.87720388174057007, 0.882088840007782, 0.88688904047012329,
    0.89160317182540894, 0.896230161190033, 0.90076881647109985,
    0.90521794557571411, 0.90957659482955933, 0.91384351253509521,
    0.91801780462265015, 0.92209833860397339, 0.92608410120010376,
    0.92997413873672485, 0.93376743793487549, 0.937463104724884,
    0.94106024503707886, 0.94455790519714355, 0.94795525074005127,
    0.95125144720077515, 0.95444566011428833, 0.95753711462020874,
    0.9605250358581543, 0.96340864896774292, 0.96618729829788208,
    0.9688602089881897, 0.97142684459686279, 0.97388643026351929,
    0.9762384295463562, 0.97848230600357056, 0.98061740398406982,
    0.98264330625534058, 0.98455935716629028, 0.98636519908905029,
    0.98806041479110718, 0.989644467830658, 0.991117000579834,
    0.99247771501541138, 0.99372619390487671, 0.99486219882965088,
    0.99588537216186523, 0.99679553508758545, 0.99759238958358765,
    0.9982757568359375, 0.99884551763534546, 0.9993014931678772,
    0.99964356422424316, 0.99987167119979858, 0.99998575448989868,
    0.99998575448989868, 0.99987167119979858, 0.99964356422424316,
    0.9993014931678772, 0.99884551763534546, 0.9982757568359375,
    0.99759238958358765, 0.99679553508758545, 0.99588537216186523,
    0.99486219882965088, 0.99372619390487671, 0.99247771501541138,
    0.991117000579834, 0.989644467830658, 0.98806041479110718,
    0.98636519908905029, 0.98455935716629028, 0.98264330625534058,
    0.98061740398406982, 0.97848230600357056, 0.9762384295463562,
    0.97388643026351929, 0.97142684459686279, 0.9688602089881897,
    0.96618729829788208, 0.96340864896774292, 0.9605250358581543,
    0.95753711462020874, 0.95444566011428833, 0.95125144720077515,
    0.94795525074005127, 0.94455790519714355, 0.94106024503707886,
    0.937463104724884, 0.93376743793487549, 0.92997413873672485,
    0.92608410120010376, 0.92209833860397339, 0.91801780462265015,
    0.91384351253509521, 0.90957659482955933, 0.90521794557571411,
    0.90076881647109985, 0.896230161190033, 0.89160317182540894,
    0.88688904047012329, 0.882088840007782, 0.87720388174057007,
    0.87223523855209351, 0.86718422174453735, 0.86205208301544189,
    0.85684007406234741, 0.851549506187439, 0.84618169069290161,
    0.84073793888092041, 0.8352196216583252, 0.8296281099319458,
    0.82396471500396729, 0.81823098659515381, 0.81242823600769043,
    0.80655789375305176, 0.800621509552002, 0.79462045431137085,
    0.78855627775192261, 0.78243046998977661, 0.77624452114105225,
    0.76999998092651367, 0.76369845867156982, 0.75734144449234009,
    0.75093048810958862, 0.74446731805801392, 0.73795336484909058,
    0.73139035701751709, 0.72477990388870239, 0.71812361478805542,
    0.71142315864562988, 0.70468020439147949, 0.69789636135101318,
    0.69107341766357422, 0.68421298265457153, 0.67731678485870361,
    0.670386552810669, 0.663424015045166, 0.65643084049224854,
    0.64940881729125977, 0.64235961437225342, 0.63528507947921753,
    0.62818688154220581, 0.6210668683052063, 0.61392670869827271,
    0.60676819086074829, 0.59959316253662109, 0.5924033522605896,
    0.58520054817199707, 0.577986478805542, 0.57076305150985718,
    0.56353199481964111, 0.55629509687423706, 0.54905414581298828,
    0.541810929775238, 0.53456729650497437, 0.52732497453689575,
    0.520085871219635, 0.51285165548324585, 0.50562417507171631,
    0.49840518832206726, 0.49119654297828674, 0.484000027179718,
    0.47681736946105957, 0.46965038776397705, 0.46250084042549133,
    0.45537051558494568, 0.44826117157936096, 0.44117459654808044,
    0.43411248922348022, 0.42707666754722595, 0.42006886005401611,
    0.41309076547622681, 0.40614414215087891, 0.3992307186126709,
    0.39235222339630127, 0.38551032543182373, 0.37870672345161438,
    0.37194311618804932, 0.36522120237350464, 0.35854262113571167,
    0.35190904140472412, 0.34532210230827332, 0.33878341317176819,
    0.33229464292526245, 0.32585740089416504, 0.31947323679924011,
    0.31314373016357422, 0.30687052011489868, 0.30065509676933289,
    0.29449903964996338, 0.28840383887290955, 0.28237104415893555,
    0.27640214562416077, 0.27049857378005981, 0.26466187834739685,
    0.25889343023300171, 0.25319468975067139, 0.2475670725107193,
    0.24201197922229767, 0.23653076589107513, 0.23112481832504272,
    0.2257954478263855, 0.22054401040077209, 0.215371772646904,
    0.21028004586696625, 0.20527006685733795, 0.20034310221672058,
    0.19550037384033203, 0.19074305891990662, 0.18607234954833984,
    0.18148940801620483, 0.17699536681175232, 0.17259134352207184,
    0.16827842593193054, 0.16405768692493439, 0.15993016958236694,
    0.15589688718318939, 0.15195886790752411, 0.1481170654296875,
    0.14437244832515717, 0.14072592556476593, 0.13717842102050781,
    0.13373079895973206, 0.1303839236497879, 0.12713862955570221,
    0.12399570643901825, 0.1209559440612793, 0.11802008748054504,
    0.11518887430429459, 0.11246300488710403, 0.10984314978122711,
    0.10732996463775635, 0.10492406785488129, 0.10262606292963028,
    0.1004365086555481, 0.098355956375598907, 0.0963849201798439,
    0.094523891806602478, 0.092773325741291046, 0.091133661568164825,
    0.089605309069156647, 0.088188633322715759, 0.086883999407291412,
    0.085691727697849274, 0.084612108767032623, 0.083645418286323547,
    0.082791887223720551, 0.082051731646060944, 0.08142513781785965,
    0.0809122622013092, 0.080513216555118561, 0.080228120088577271,
    0.080057032406330109, 0.079999998211860657 };

  float y[400];
  creal32_T value[400];
  static const float fv1[400] = { 0.08F, 0.0800570324F, 0.0802281201F,
    0.0805132166F, 0.0809122622F, 0.0814251378F, 0.0820517316F, 0.0827918872F,
    0.0836454183F, 0.0846121088F, 0.0856917277F, 0.086884F, 0.0881886333F,
    0.0896053091F, 0.0911336616F, 0.0927733257F, 0.0945238918F, 0.0963849202F,
    0.0983559564F, 0.100436509F, 0.102626063F, 0.104924068F, 0.107329965F,
    0.10984315F, 0.112463005F, 0.115188874F, 0.118020087F, 0.120955944F,
    0.123995706F, 0.12713863F, 0.130383924F, 0.133730799F, 0.137178421F,
    0.140725926F, 0.144372448F, 0.148117065F, 0.151958868F, 0.155896887F,
    0.15993017F, 0.164057687F, 0.168278426F, 0.172591344F, 0.176995367F,
    0.181489408F, 0.18607235F, 0.190743059F, 0.195500374F, 0.200343102F,
    0.205270067F, 0.210280046F, 0.215371773F, 0.22054401F, 0.225795448F,
    0.231124818F, 0.236530766F, 0.242011979F, 0.247567073F, 0.25319469F,
    0.25889343F, 0.264661878F, 0.270498574F, 0.276402146F, 0.282371044F,
    0.288403839F, 0.29449904F, 0.300655097F, 0.30687052F, 0.31314373F,
    0.319473237F, 0.325857401F, 0.332294643F, 0.338783413F, 0.345322102F,
    0.351909041F, 0.358542621F, 0.365221202F, 0.371943116F, 0.378706723F,
    0.385510325F, 0.392352223F, 0.399230719F, 0.406144142F, 0.413090765F,
    0.42006886F, 0.427076668F, 0.434112489F, 0.441174597F, 0.448261172F,
    0.455370516F, 0.46250084F, 0.469650388F, 0.476817369F, 0.484000027F,
    0.491196543F, 0.498405188F, 0.505624175F, 0.512851655F, 0.520085871F,
    0.527325F, 0.534567297F, 0.54181093F, 0.549054146F, 0.556295097F, 0.563532F,
    0.570763052F, 0.577986479F, 0.585200548F, 0.592403352F, 0.599593163F,
    0.606768191F, 0.613926709F, 0.621066868F, 0.628186882F, 0.635285079F,
    0.642359614F, 0.649408817F, 0.65643084F, 0.663424F, 0.670386553F,
    0.677316785F, 0.684213F, 0.691073418F, 0.697896361F, 0.704680204F,
    0.711423159F, 0.718123615F, 0.724779904F, 0.731390357F, 0.737953365F,
    0.744467318F, 0.750930488F, 0.757341444F, 0.763698459F, 0.77F, 0.776244521F,
    0.78243047F, 0.788556278F, 0.794620454F, 0.80062151F, 0.806557894F,
    0.812428236F, 0.818231F, 0.823964715F, 0.82962811F, 0.835219622F,
    0.840737939F, 0.846181691F, 0.851549506F, 0.856840074F, 0.862052083F,
    0.867184222F, 0.872235239F, 0.877203882F, 0.88208884F, 0.88688904F,
    0.891603172F, 0.896230161F, 0.900768816F, 0.905217946F, 0.909576595F,
    0.913843513F, 0.918017805F, 0.922098339F, 0.926084101F, 0.929974139F,
    0.933767438F, 0.937463105F, 0.941060245F, 0.944557905F, 0.947955251F,
    0.951251447F, 0.95444566F, 0.957537115F, 0.960525036F, 0.963408649F,
    0.966187298F, 0.968860209F, 0.971426845F, 0.97388643F, 0.97623843F,
    0.978482306F, 0.980617404F, 0.982643306F, 0.984559357F, 0.986365199F,
    0.988060415F, 0.989644468F, 0.991117F, 0.992477715F, 0.993726194F,
    0.994862199F, 0.995885372F, 0.996795535F, 0.99759239F, 0.998275757F,
    0.998845518F, 0.999301493F, 0.999643564F, 0.999871671F, 0.999985754F,
    0.999985754F, 0.999871671F, 0.999643564F, 0.999301493F, 0.998845518F,
    0.998275757F, 0.99759239F, 0.996795535F, 0.995885372F, 0.994862199F,
    0.993726194F, 0.992477715F, 0.991117F, 0.989644468F, 0.988060415F,
    0.986365199F, 0.984559357F, 0.982643306F, 0.980617404F, 0.978482306F,
    0.97623843F, 0.97388643F, 0.971426845F, 0.968860209F, 0.966187298F,
    0.963408649F, 0.960525036F, 0.957537115F, 0.95444566F, 0.951251447F,
    0.947955251F, 0.944557905F, 0.941060245F, 0.937463105F, 0.933767438F,
    0.929974139F, 0.926084101F, 0.922098339F, 0.918017805F, 0.913843513F,
    0.909576595F, 0.905217946F, 0.900768816F, 0.896230161F, 0.891603172F,
    0.88688904F, 0.88208884F, 0.877203882F, 0.872235239F, 0.867184222F,
    0.862052083F, 0.856840074F, 0.851549506F, 0.846181691F, 0.840737939F,
    0.835219622F, 0.82962811F, 0.823964715F, 0.818231F, 0.812428236F,
    0.806557894F, 0.80062151F, 0.794620454F, 0.788556278F, 0.78243047F,
    0.776244521F, 0.77F, 0.763698459F, 0.757341444F, 0.750930488F, 0.744467318F,
    0.737953365F, 0.731390357F, 0.724779904F, 0.718123615F, 0.711423159F,
    0.704680204F, 0.697896361F, 0.691073418F, 0.684213F, 0.677316785F,
    0.670386553F, 0.663424F, 0.65643084F, 0.649408817F, 0.642359614F,
    0.635285079F, 0.628186882F, 0.621066868F, 0.613926709F, 0.606768191F,
    0.599593163F, 0.592403352F, 0.585200548F, 0.577986479F, 0.570763052F,
    0.563532F, 0.556295097F, 0.549054146F, 0.54181093F, 0.534567297F, 0.527325F,
    0.520085871F, 0.512851655F, 0.505624175F, 0.498405188F, 0.491196543F,
    0.484000027F, 0.476817369F, 0.469650388F, 0.46250084F, 0.455370516F,
    0.448261172F, 0.441174597F, 0.434112489F, 0.427076668F, 0.42006886F,
    0.413090765F, 0.406144142F, 0.399230719F, 0.392352223F, 0.385510325F,
    0.378706723F, 0.371943116F, 0.365221202F, 0.358542621F, 0.351909041F,
    0.345322102F, 0.338783413F, 0.332294643F, 0.325857401F, 0.319473237F,
    0.31314373F, 0.30687052F, 0.300655097F, 0.29449904F, 0.288403839F,
    0.282371044F, 0.276402146F, 0.270498574F, 0.264661878F, 0.25889343F,
    0.25319469F, 0.247567073F, 0.242011979F, 0.236530766F, 0.231124818F,
    0.225795448F, 0.22054401F, 0.215371773F, 0.210280046F, 0.205270067F,
    0.200343102F, 0.195500374F, 0.190743059F, 0.18607235F, 0.181489408F,
    0.176995367F, 0.172591344F, 0.168278426F, 0.164057687F, 0.15993017F,
    0.155896887F, 0.151958868F, 0.148117065F, 0.144372448F, 0.140725926F,
    0.137178421F, 0.133730799F, 0.130383924F, 0.12713863F, 0.123995706F,
    0.120955944F, 0.118020087F, 0.115188874F, 0.112463005F, 0.10984315F,
    0.107329965F, 0.104924068F, 0.102626063F, 0.100436509F, 0.0983559564F,
    0.0963849202F, 0.0945238918F, 0.0927733257F, 0.0911336616F, 0.0896053091F,
    0.0881886333F, 0.086884F, 0.0856917277F, 0.0846121088F, 0.0836454183F,
    0.0827918872F, 0.0820517316F, 0.0814251378F, 0.0809122622F, 0.0805132166F,
    0.0802281201F, 0.0800570324F, 0.08F };

  int k;
  float temp_re;
  creal32_T b_value[512];
  float twid_im;
  float log_sigma_k[512];
  float noisy_ps[512];
  float posteri[512];
  int i;
  emxArray_real32_T *b_b;
  int joffset;
  int ix;
  float posteri_prime[512];
  emxArray_real32_T *r0;
  float b_posteri_prime[512];
  int jA2;
  emxArray_real32_T *wind;
  int b_j;
  creal32_T b_y1[512];
  boolean_T tst;
  float temp_im;
  static const float fv2[257] = { 1.0F, 0.999924719F, 0.999698818F, 0.999322414F,
    0.99879545F, 0.998118103F, 0.997290432F, 0.996312618F, 0.99518472F,
    0.993907F, 0.992479563F, 0.990902662F, 0.989176512F, 0.987301409F,
    0.985277653F, 0.983105481F, 0.980785251F, 0.97831738F, 0.975702107F,
    0.972939968F, 0.970031261F, 0.966976464F, 0.963776052F, 0.960430503F,
    0.956940353F, 0.953306F, 0.949528158F, 0.945607305F, 0.941544056F, 0.937339F,
    0.932992816F, 0.928506076F, 0.923879504F, 0.919113874F, 0.914209723F,
    0.909167945F, 0.903989315F, 0.898674488F, 0.893224299F, 0.887639642F,
    0.881921232F, 0.876070082F, 0.870086968F, 0.863972843F, 0.857728601F,
    0.851355195F, 0.84485358F, 0.838224709F, 0.831469595F, 0.824589252F,
    0.817584813F, 0.81045717F, 0.803207517F, 0.795836926F, 0.78834641F,
    0.780737221F, 0.773010433F, 0.765167236F, 0.757208824F, 0.749136388F,
    0.740951121F, 0.732654274F, 0.724247098F, 0.715730786F, 0.707106769F,
    0.698376298F, 0.689540565F, 0.680601F, 0.671559F, 0.662415802F, 0.653172851F,
    0.643831551F, 0.634393334F, 0.624859512F, 0.615231633F, 0.605511F,
    0.59569931F, 0.585797906F, 0.575808227F, 0.565731823F, 0.555570245F,
    0.545325041F, 0.534997642F, 0.524589717F, 0.514102757F, 0.50353837F,
    0.492898226F, 0.482183754F, 0.471396744F, 0.460538715F, 0.449611336F,
    0.438616246F, 0.427555084F, 0.416429579F, 0.40524134F, 0.393992066F,
    0.382683456F, 0.371317208F, 0.359895051F, 0.348418683F, 0.336889863F,
    0.32531032F, 0.313681751F, 0.302005947F, 0.290284663F, 0.27851969F,
    0.266712785F, 0.254865676F, 0.242980197F, 0.231058121F, 0.219101235F,
    0.207111388F, 0.195090324F, 0.183039889F, 0.170961902F, 0.15885815F,
    0.146730468F, 0.134580716F, 0.122410677F, 0.110222206F, 0.0980171412F,
    0.0857973173F, 0.0735645667F, 0.0613207407F, 0.0490676761F, 0.0368072242F,
    0.024541229F, 0.0122715384F, 0.0F, -0.0122715384F, -0.024541229F,
    -0.0368072242F, -0.0490676761F, -0.0613207407F, -0.0735645667F,
    -0.0857973173F, -0.0980171412F, -0.110222206F, -0.122410677F, -0.134580716F,
    -0.146730468F, -0.15885815F, -0.170961902F, -0.183039889F, -0.195090324F,
    -0.207111388F, -0.219101235F, -0.231058121F, -0.242980197F, -0.254865676F,
    -0.266712785F, -0.27851969F, -0.290284663F, -0.302005947F, -0.313681751F,
    -0.32531032F, -0.336889863F, -0.348418683F, -0.359895051F, -0.371317208F,
    -0.382683456F, -0.393992066F, -0.40524134F, -0.416429579F, -0.427555084F,
    -0.438616246F, -0.449611336F, -0.460538715F, -0.471396744F, -0.482183754F,
    -0.492898226F, -0.50353837F, -0.514102757F, -0.524589717F, -0.534997642F,
    -0.545325041F, -0.555570245F, -0.565731823F, -0.575808227F, -0.585797906F,
    -0.59569931F, -0.605511F, -0.615231633F, -0.624859512F, -0.634393334F,
    -0.643831551F, -0.653172851F, -0.662415802F, -0.671559F, -0.680601F,
    -0.689540565F, -0.698376298F, -0.707106769F, -0.715730786F, -0.724247098F,
    -0.732654274F, -0.740951121F, -0.749136388F, -0.757208824F, -0.765167236F,
    -0.773010433F, -0.780737221F, -0.78834641F, -0.795836926F, -0.803207517F,
    -0.81045717F, -0.817584813F, -0.824589252F, -0.831469595F, -0.838224709F,
    -0.84485358F, -0.851355195F, -0.857728601F, -0.863972843F, -0.870086968F,
    -0.876070082F, -0.881921232F, -0.887639642F, -0.893224299F, -0.898674488F,
    -0.903989315F, -0.909167945F, -0.914209723F, -0.919113874F, -0.923879504F,
    -0.928506076F, -0.932992816F, -0.937339F, -0.941544056F, -0.945607305F,
    -0.949528158F, -0.953306F, -0.956940353F, -0.960430503F, -0.963776052F,
    -0.966976464F, -0.970031261F, -0.972939968F, -0.975702107F, -0.97831738F,
    -0.980785251F, -0.983105481F, -0.985277653F, -0.987301409F, -0.989176512F,
    -0.990902662F, -0.992479563F, -0.993907F, -0.99518472F, -0.996312618F,
    -0.997290432F, -0.998118103F, -0.99879545F, -0.999322414F, -0.999698818F,
    -0.999924719F, -1.0F };

  static const float fv3[257] = { 0.0F, 0.0122715384F, 0.024541229F,
    0.0368072242F, 0.0490676761F, 0.0613207407F, 0.0735645667F, 0.0857973173F,
    0.0980171412F, 0.110222206F, 0.122410677F, 0.134580716F, 0.146730468F,
    0.15885815F, 0.170961902F, 0.183039889F, 0.195090324F, 0.207111388F,
    0.219101235F, 0.231058121F, 0.242980197F, 0.254865676F, 0.266712785F,
    0.27851969F, 0.290284663F, 0.302005947F, 0.313681751F, 0.32531032F,
    0.336889863F, 0.348418683F, 0.359895051F, 0.371317208F, 0.382683456F,
    0.393992066F, 0.40524134F, 0.416429579F, 0.427555084F, 0.438616246F,
    0.449611336F, 0.460538715F, 0.471396744F, 0.482183754F, 0.492898226F,
    0.50353837F, 0.514102757F, 0.524589717F, 0.534997642F, 0.545325041F,
    0.555570245F, 0.565731823F, 0.575808227F, 0.585797906F, 0.59569931F,
    0.605511F, 0.615231633F, 0.624859512F, 0.634393334F, 0.643831551F,
    0.653172851F, 0.662415802F, 0.671559F, 0.680601F, 0.689540565F, 0.698376298F,
    0.707106769F, 0.715730786F, 0.724247098F, 0.732654274F, 0.740951121F,
    0.749136388F, 0.757208824F, 0.765167236F, 0.773010433F, 0.780737221F,
    0.78834641F, 0.795836926F, 0.803207517F, 0.81045717F, 0.817584813F,
    0.824589252F, 0.831469595F, 0.838224709F, 0.84485358F, 0.851355195F,
    0.857728601F, 0.863972843F, 0.870086968F, 0.876070082F, 0.881921232F,
    0.887639642F, 0.893224299F, 0.898674488F, 0.903989315F, 0.909167945F,
    0.914209723F, 0.919113874F, 0.923879504F, 0.928506076F, 0.932992816F,
    0.937339F, 0.941544056F, 0.945607305F, 0.949528158F, 0.953306F, 0.956940353F,
    0.960430503F, 0.963776052F, 0.966976464F, 0.970031261F, 0.972939968F,
    0.975702107F, 0.97831738F, 0.980785251F, 0.983105481F, 0.985277653F,
    0.987301409F, 0.989176512F, 0.990902662F, 0.992479563F, 0.993907F,
    0.99518472F, 0.996312618F, 0.997290432F, 0.998118103F, 0.99879545F,
    0.999322414F, 0.999698818F, 0.999924719F, 1.0F, 0.999924719F, 0.999698818F,
    0.999322414F, 0.99879545F, 0.998118103F, 0.997290432F, 0.996312618F,
    0.99518472F, 0.993907F, 0.992479563F, 0.990902662F, 0.989176512F,
    0.987301409F, 0.985277653F, 0.983105481F, 0.980785251F, 0.97831738F,
    0.975702107F, 0.972939968F, 0.970031261F, 0.966976464F, 0.963776052F,
    0.960430503F, 0.956940353F, 0.953306F, 0.949528158F, 0.945607305F,
    0.941544056F, 0.937339F, 0.932992816F, 0.928506076F, 0.923879504F,
    0.919113874F, 0.914209723F, 0.909167945F, 0.903989315F, 0.898674488F,
    0.893224299F, 0.887639642F, 0.881921232F, 0.876070082F, 0.870086968F,
    0.863972843F, 0.857728601F, 0.851355195F, 0.84485358F, 0.838224709F,
    0.831469595F, 0.824589252F, 0.817584813F, 0.81045717F, 0.803207517F,
    0.795836926F, 0.78834641F, 0.780737221F, 0.773010433F, 0.765167236F,
    0.757208824F, 0.749136388F, 0.740951121F, 0.732654274F, 0.724247098F,
    0.715730786F, 0.707106769F, 0.698376298F, 0.689540565F, 0.680601F, 0.671559F,
    0.662415802F, 0.653172851F, 0.643831551F, 0.634393334F, 0.624859512F,
    0.615231633F, 0.605511F, 0.59569931F, 0.585797906F, 0.575808227F,
    0.565731823F, 0.555570245F, 0.545325041F, 0.534997642F, 0.524589717F,
    0.514102757F, 0.50353837F, 0.492898226F, 0.482183754F, 0.471396744F,
    0.460538715F, 0.449611336F, 0.438616246F, 0.427555084F, 0.416429579F,
    0.40524134F, 0.393992066F, 0.382683456F, 0.371317208F, 0.359895051F,
    0.348418683F, 0.336889863F, 0.32531032F, 0.313681751F, 0.302005947F,
    0.290284663F, 0.27851969F, 0.266712785F, 0.254865676F, 0.242980197F,
    0.231058121F, 0.219101235F, 0.207111388F, 0.195090324F, 0.183039889F,
    0.170961902F, 0.15885815F, 0.146730468F, 0.134580716F, 0.122410677F,
    0.110222206F, 0.0980171412F, 0.0857973173F, 0.0735645667F, 0.0613207407F,
    0.0490676761F, 0.0368072242F, 0.024541229F, 0.0122715384F, 0.0F };

  int ihi;
  (void)Srate;
  for (nB = 0; nB < 200; nB++) {
    fv0[nB] = buffer[200 + nB];
    fv0[nB + 200] = frame_in[nB];
  }

  memcpy(&buffer[0], &fv0[0], 400U * sizeof(float));

  /*  frame number counter */
  /*  frame number counter */
  if (!noise_ps_not_empty) {
    nB = noise_ps->size[0] * noise_ps->size[1];
    noise_ps->size[0] = 1;
    noise_ps->size[1] = 512;
    emxEnsureCapacity((emxArray__common *)noise_ps, nB, (int)sizeof(float));
    for (nB = 0; nB < 512; nB++) {
      noise_ps->data[nB] = 0.0F;
    }

    noise_ps_not_empty = true;
  }

  if (!G_prev_not_empty) {
    nB = G_prev->size[0] * G_prev->size[1];
    G_prev->size[0] = 1;
    G_prev->size[1] = 512;
    emxEnsureCapacity((emxArray__common *)G_prev, nB, (int)sizeof(float));
    for (nB = 0; nB < 512; nB++) {
      G_prev->data[nB] = 0.0F;
    }

    G_prev_not_empty = true;
  }

  if (!posteri_prev_not_empty) {
    nB = posteri_prev->size[0] * posteri_prev->size[1];
    posteri_prev->size[0] = 1;
    posteri_prev->size[1] = 512;
    emxEnsureCapacity((emxArray__common *)posteri_prev, nB, (int)sizeof(float));
    for (nB = 0; nB < 512; nB++) {
      posteri_prev->data[nB] = 0.0F;
    }

    posteri_prev_not_empty = true;
  }

  if (!overlap_not_empty) {
    nB = overlap->size[0] * overlap->size[1];
    overlap->size[0] = 1;
    overlap->size[1] = 200;
    emxEnsureCapacity((emxArray__common *)overlap, nB, (int)sizeof(float));
    for (nB = 0; nB < 200; nB++) {
      overlap->data[nB] = 0.0F;
    }

    overlap_not_empty = true;
  }

  /*  fs = 8000; */
  /*  set parameter values */
  /*  smoothing factor in noise spectrum update */
  /*  smoothing factor in priori update */
  /*  VAD threshold */
  /*  L is frame length  */
  /*  hamming window */
  /*  U= ( hamming_win'* hamming_win)/ L; % normalization factor */
  /*  U2 = ( hamming(fft_len)'* hamming(fft_len))/ fft_len; */
  d0 = 0.0;
  for (nB = 0; nB < 400; nB++) {
    d0 += a[nB] * b[nB];
  }

  U2 = (float)d0 / 512.0F;

  /*  normalization factor */
  /*  SPL calculation */
  if (update == 1.0F) {
    for (nB = 0; nB < 400; nB++) {
      y[nB] = buffer[nB] * fv1[nB];
    }

    fft(y, value);
    for (k = 0; k < 400; k++) {
      temp_re = rt_hypotf_snf(value[k].re, value[k].im);
      y[k] = temp_re * temp_re;
    }

    temp_re = y[0];
    for (k = 0; k < 399; k++) {
      temp_re += y[k + 1];
    }

    SPL = rt_roundf_snf(10.0F * (float)log10((float)sqrt(temp_re / 400.0F) /
      2.0E-5F + 1.0F));
    update = 2.0F;
  } else if ((update != 1.0F) && (update <= 999.0F)) {
    update++;
  } else {
    if (update == 1000.0F) {
      update = 1.0F;
    }
  }

  if (SPL <= spl_threshold) {
    if (count == 1.0F) {
      memcpy(&out[0], &buffer[0], 200U * sizeof(float));
    } else {
      for (nB = 0; nB < 200; nB++) {
        out[nB] = overlap_spl[nB] + buffer[nB];
      }
    }

    memcpy(&overlap_spl[0], &buffer[200], 200U * sizeof(float));
    count++;
    j = 1.0F;
    nB = noise_ps->size[0] * noise_ps->size[1];
    noise_ps->size[0] = 400;
    noise_ps->size[1] = 1;
    emxEnsureCapacity((emxArray__common *)noise_ps, nB, (int)sizeof(float));
    for (nB = 0; nB < 400; nB++) {
      noise_ps->data[nB] = 0.0F;
    }

    noise_ps_not_empty = true;
    nB = G_prev->size[0] * G_prev->size[1];
    G_prev->size[0] = 400;
    G_prev->size[1] = 1;
    emxEnsureCapacity((emxArray__common *)G_prev, nB, (int)sizeof(float));
    for (nB = 0; nB < 400; nB++) {
      G_prev->data[nB] = 0.0F;
    }

    G_prev_not_empty = true;
    nB = posteri_prev->size[0] * posteri_prev->size[1];
    posteri_prev->size[0] = 400;
    posteri_prev->size[1] = 1;
    emxEnsureCapacity((emxArray__common *)posteri_prev, nB, (int)sizeof(float));
    for (nB = 0; nB < 400; nB++) {
      posteri_prev->data[nB] = 0.0F;
    }

    posteri_prev_not_empty = true;
    nB = overlap->size[0] * overlap->size[1];
    overlap->size[0] = 200;
    overlap->size[1] = 1;
    emxEnsureCapacity((emxArray__common *)overlap, nB, (int)sizeof(float));
    for (nB = 0; nB < 200; nB++) {
      overlap->data[nB] = 0.0F;
    }

    overlap_not_empty = true;
  } else {
    if (j < 7.0F) {
      for (nB = 0; nB < 400; nB++) {
        y[nB] = buffer[nB] * fv1[nB];
      }

      b_fft(y, b_value);
      for (k = 0; k < 512; k++) {
        temp_re = rt_hypotf_snf(b_value[k].re, b_value[k].im);
        log_sigma_k[k] = temp_re * temp_re;
      }

      twid_im = 512.0F * U2;
      nB = noise_ps->size[0] * noise_ps->size[1];
      noise_ps->size[0] = 1;
      noise_ps->size[1] = 512;
      emxEnsureCapacity((emxArray__common *)noise_ps, nB, (int)sizeof(float));
      for (nB = 0; nB < 512; nB++) {
        noise_ps->data[noise_ps->size[0] * nB] = noise_ps->data[nB] +
          log_sigma_k[nB] / twid_im;
      }

      noise_ps_not_empty = true;
      memcpy(&out[0], &frame_in[0], 200U * sizeof(float));
    } else {
      for (nB = 0; nB < 400; nB++) {
        y[nB] = buffer[nB] * fv1[nB];
      }

      b_fft(y, b_value);
      twid_im = 512.0F * U2;
      for (k = 0; k < 512; k++) {
        temp_re = rt_hypotf_snf(b_value[k].re, b_value[k].im);
        noisy_ps[k] = temp_re * temp_re / twid_im;
      }

      if (j == 7.0F) {
        /*  initialize posteri */
        nB = noise_ps->size[0] * noise_ps->size[1];
        emxEnsureCapacity((emxArray__common *)noise_ps, nB, (int)sizeof(float));
        nB = noise_ps->size[0];
        joffset = noise_ps->size[1];
        ix = nB * joffset;
        for (nB = 0; nB < ix; nB++) {
          noise_ps->data[nB] /= 6.0F;
        }

        noise_ps_not_empty = true;
        rdivide(noisy_ps, noise_ps, posteri);
        for (i = 0; i < 512; i++) {
          U2 = posteri[i] - 1.0F;
          if (posteri[i] - 1.0F < 0.0F) {
            U2 = 0.0F;
          }

          U2 = 0.98F + 0.0199999809F * U2;
          posteri_prime[i] = U2;
        }
      } else {
        rdivide(noisy_ps, noise_ps, posteri);
        for (i = 0; i < 512; i++) {
          U2 = posteri[i] - 1.0F;
          if (posteri[i] - 1.0F < 0.0F) {
            U2 = 0.0F;
          }

          posteri_prime[i] = U2;
        }

        emxInit_real32_T(&b_b, 2);
        b_power(G_prev, b_b);
        for (nB = 0; nB < 512; nB++) {
          U2 = 0.98F * b_b->data[nB] * posteri_prev->data[nB] + 0.0199999809F *
            posteri_prime[nB];
          posteri_prime[nB] = U2;
        }

        emxFree_real32_T(&b_b);
      }

      for (k = 0; k < 512; k++) {
        log_sigma_k[k] = posteri[k] * posteri_prime[k] / (1.0F + posteri_prime[k])
          - (float)log(1.0F + posteri_prime[k]);
      }

      temp_re = log_sigma_k[0];
      for (k = 0; k < 511; k++) {
        temp_re += log_sigma_k[k + 1];
      }

      if (temp_re / 400.0F < 0.15F) {
        emxInit_real32_T(&r0, 2);

        /*  noise only frame found */
        nB = r0->size[0] * r0->size[1];
        r0->size[0] = noise_ps->size[0];
        r0->size[1] = noise_ps->size[1];
        emxEnsureCapacity((emxArray__common *)r0, nB, (int)sizeof(float));
        ix = noise_ps->size[1];
        for (nB = 0; nB < ix; nB++) {
          jA2 = noise_ps->size[0];
          for (joffset = 0; joffset < jA2; joffset++) {
            r0->data[joffset + r0->size[0] * nB] = 0.98F * noise_ps->
              data[joffset + noise_ps->size[0] * nB];
          }
        }

        nB = noise_ps->size[0] * noise_ps->size[1];
        noise_ps->size[0] = 1;
        noise_ps->size[1] = 512;
        emxEnsureCapacity((emxArray__common *)noise_ps, nB, (int)sizeof(float));
        for (nB = 0; nB < 512; nB++) {
          noise_ps->data[noise_ps->size[0] * nB] = r0->data[nB] + 0.0199999809F *
            noisy_ps[nB];
        }

        emxFree_real32_T(&r0);
        noise_ps_not_empty = true;

        /* vad( n_start: n_start+ L- 1)= 0; */
      }

      /*      ===end of vad=== */
      /* EFFICIENT MUSICAL NOISE SUPPRESSION FOR SPEECH ENHANCEMENT SYSTEMS */
      /*  postfilter applied to the gain function */
      b_abs(b_value, log_sigma_k);
      for (k = 0; k < 512; k++) {
        U2 = (float)sqrt(posteri_prime[k] / (1.0F + posteri_prime[k]));
        b_posteri_prime[k] = U2 * log_sigma_k[k];
        posteri_prime[k] = U2;
      }

      power(b_posteri_prime, log_sigma_k);
      temp_re = log_sigma_k[0];
      for (k = 0; k < 511; k++) {
        temp_re += log_sigma_k[k + 1];
      }

      for (k = 0; k < 512; k++) {
        U2 = rt_hypotf_snf(b_value[k].re, b_value[k].im);
        log_sigma_k[k] = U2 * U2;
      }

      U2 = log_sigma_k[0];
      for (k = 0; k < 511; k++) {
        U2 += log_sigma_k[k + 1];
      }

      U2 = temp_re / (U2 + 1.0E-7F);
      twid_im = U2;
      for (i = 0; i < 1; i++) {
        if (U2 >= 0.4F) {
          twid_im = 1.0F;
        }
      }

      if (twid_im == 1.0F) {
        U2 = 1.0F;
      } else {
        U2 = 2.0F * rt_roundf_snf((1.0F - twid_im / 0.4F) * 40.0F) + 1.0F;
      }

      emxInit_real32_T(&wind, 2);

      /*      assert(N<256); */
      twid_im = 1.0F / U2;
      nB = wind->size[0] * wind->size[1];
      wind->size[0] = 1;
      wind->size[1] = (int)U2;
      emxEnsureCapacity((emxArray__common *)wind, nB, (int)sizeof(float));
      ix = (int)U2;
      for (nB = 0; nB < ix; nB++) {
        wind->data[nB] = twid_im;
      }

      for (k = 0; k < 512; k++) {
        b_posteri_prime[k] = (float)fabs(posteri_prime[k]);
      }

      nB = wind->size[1];
      if (wind->size[1] < 1) {
        joffset = 0;
      } else {
        joffset = (wind->size[1] - 1) / 2;
        if (joffset << 1 != wind->size[1] - 1) {
          joffset++;
        }
      }

      if (wind->size[1] == 0) {
        memset(&noisy_ps[0], 0, sizeof(float) << 9);
      } else {
        for (ix = 0; ix < 512; ix++) {
          b_j = (ix + joffset) + 1;
          if (512 <= b_j) {
            jA2 = 512;
          } else {
            jA2 = b_j;
          }

          U2 = 0.0F;
          if (nB < b_j + 1) {
            k = (b_j - nB) + 1;
          } else {
            k = 1;
          }

          while (k <= jA2) {
            U2 += b_posteri_prime[k - 1] * wind->data[b_j - k];
            k++;
          }

          noisy_ps[ix] = U2;
        }
      }

      emxFree_real32_T(&wind);

      /* end of postfilter */
      for (nB = 0; nB < 512; nB++) {
        b_value[nB].re *= noisy_ps[nB];
        b_value[nB].im *= noisy_ps[nB];
      }

      ix = 0;
      jA2 = 0;
      nB = 0;
      for (i = 0; i < 511; i++) {
        b_y1[nB] = b_value[ix];
        joffset = 512;
        tst = true;
        while (tst) {
          joffset >>= 1;
          jA2 ^= joffset;
          tst = ((jA2 & joffset) == 0);
        }

        nB = jA2;
        ix++;
      }

      b_y1[nB] = b_value[ix];
      for (i = 0; i <= 511; i += 2) {
        temp_re = b_y1[i + 1].re;
        temp_im = b_y1[i + 1].im;
        b_y1[i + 1].re = b_y1[i].re - b_y1[i + 1].re;
        b_y1[i + 1].im = b_y1[i].im - b_y1[i + 1].im;
        b_y1[i].re += temp_re;
        b_y1[i].im += temp_im;
      }

      ix = 2;
      nB = 4;
      k = 128;
      joffset = 509;
      while (k > 0) {
        for (i = 0; i < joffset; i += nB) {
          temp_re = b_y1[i + ix].re;
          temp_im = b_y1[i + ix].im;
          b_y1[i + ix].re = b_y1[i].re - temp_re;
          b_y1[i + ix].im = b_y1[i].im - temp_im;
          b_y1[i].re += temp_re;
          b_y1[i].im += temp_im;
        }

        jA2 = 1;
        for (b_j = k; b_j < 256; b_j += k) {
          U2 = fv2[b_j];
          twid_im = fv3[b_j];
          i = jA2;
          ihi = jA2 + joffset;
          while (i < ihi) {
            temp_re = U2 * b_y1[i + ix].re - twid_im * b_y1[i + ix].im;
            temp_im = U2 * b_y1[i + ix].im + twid_im * b_y1[i + ix].re;
            b_y1[i + ix].re = b_y1[i].re - temp_re;
            b_y1[i + ix].im = b_y1[i].im - temp_im;
            b_y1[i].re += temp_re;
            b_y1[i].im += temp_im;
            i += nB;
          }

          jA2++;
        }

        k /= 2;
        ix = nB;
        nB <<= 1;
        joffset -= ix;
      }

      for (nB = 0; nB < 512; nB++) {
        b_y1[nB].re *= 0.001953125F;
        b_y1[nB].im *= 0.001953125F;
        log_sigma_k[nB] = b_y1[nB].re;
      }

      if (j == 7.0F) {
        memcpy(&out[0], &log_sigma_k[0], 200U * sizeof(float));
      } else {
        for (nB = 0; nB < 200; nB++) {
          out[nB] = overlap->data[nB] + log_sigma_k[nB];
        }
      }

      nB = overlap->size[0] * overlap->size[1];
      overlap->size[0] = 1;
      overlap->size[1] = 200;
      emxEnsureCapacity((emxArray__common *)overlap, nB, (int)sizeof(float));
      for (nB = 0; nB < 200; nB++) {
        overlap->data[nB] = log_sigma_k[200 + nB];
      }

      overlap_not_empty = true;
      nB = G_prev->size[0] * G_prev->size[1];
      G_prev->size[0] = 1;
      G_prev->size[1] = 512;
      emxEnsureCapacity((emxArray__common *)G_prev, nB, (int)sizeof(float));
      for (nB = 0; nB < 512; nB++) {
        G_prev->data[nB] = noisy_ps[nB];
      }

      G_prev_not_empty = true;
      nB = posteri_prev->size[0] * posteri_prev->size[1];
      posteri_prev->size[0] = 1;
      posteri_prev->size[1] = 512;
      emxEnsureCapacity((emxArray__common *)posteri_prev, nB, (int)sizeof(float));
      for (nB = 0; nB < 512; nB++) {
        posteri_prev->data[nB] = posteri[nB];
      }

      posteri_prev_not_empty = true;
    }

    j++;
    memset(&overlap_spl[0], 0, 200U * sizeof(float));
    count = 1.0F;
  }
}

/*
 * Arguments    : void
 * Return Type  : void
 */
void wienerAB_free(void)
{
  emxFree_real32_T(&overlap);
  emxFree_real32_T(&posteri_prev);
  emxFree_real32_T(&G_prev);
  emxFree_real32_T(&noise_ps);
}

/*
 * Arguments    : void
 * Return Type  : void
 */
void wienerAB_init(void)
{
  emxInit_real32_T(&overlap, 2);
  emxInit_real32_T(&posteri_prev, 2);
  emxInit_real32_T(&G_prev, 2);
  emxInit_real32_T(&noise_ps, 2);
  overlap_not_empty = false;
  posteri_prev_not_empty = false;
  G_prev_not_empty = false;
  noise_ps_not_empty = false;
  memset(&buffer[0], 0, 400U * sizeof(float));
  j = 1.0F;
  count = 1.0F;
  memset(&overlap_spl[0], 0, 200U * sizeof(float));
  update = 1.0F;
  SPL = 37.0F;
}

/*
 * File trailer for wienerAB.c
 *
 * [EOF]
 */
